import logging
import time
from devices.fluke8842_gpib import Fluke8842_GPIB, FlukeResolution



class Fluke8845A_Device():
    def __init__(self, resourceName, *args, **kwargs):
        self.resourceName = resourceName
        self.device = Fluke8842_GPIB('GPIB0::1::INSTR')

    def read_voltage(self, resolution=None):
        #self.device.send_raw_command('MEAS:VOLT:DC? DEF,DEF')
        if resolution == FlukeResolution.MIN.value:
            cmd = 'MEAS:VOLT:DC? 10,%s' % FlukeResolution.MIN.value
        else:
            cmd = 'MEAS:VOLT:DC? 10'
        self.device.send_raw_command('MEAS:VOLT:DC? 10')
        r = self.device.read_data()
        voltage = float(r)
        logging.info('r=%f' % voltage)
        return voltage

    def close(self):
        self.device.fluke_close()



if __name__ == '__main__':
    
    logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s')

    card_address = 0
    instrument_address = 1
    resourceName = 'GPIB%d::%d::INSTR' % (card_address, instrument_address)
    device = Fluke8845A_Device(resourceName)

    for i in range(10):
        v = device.read_voltage()
        logging.info('v=%s' % v)

    device.close()




